using System;
using System.Web.Configuration;
using System.Xml;
using System.Collections;

namespace ComplianceFilter
{
	/// <summary>
	/// configuration section reader
	/// </summary>
	public class Configuration
	{
		private static bool _ApplyMCMSRules;
		/// <summary>
		/// do we want to apply mcms specific rules
		/// </summary>
		public static bool ApplyMCMSRules
		{
			get { return _ApplyMCMSRules; }
		}


		private static bool _RemoveControlSpans;
		/// <summary>
		/// do we want to remove controlspans ie <span id="welcome"></span>
		/// </summary>
		public static bool RemoveControlSpans
		{
			get { return _RemoveControlSpans; }
		}
		


		private static bool _RemoveComments;
		/// <summary>
		/// 
		/// </summary>
		public static bool RemoveComments
		{
			get { return _RemoveComments; }
		}

        private static bool removeIDUnderScores;
        public static bool RemoveIDUnderScores {
            get { return removeIDUnderScores; }
        }

		private static string umbracoReservedUrl="";
		/// <summary>
		/// tells system that this is umbraco, and not to use compliance filter.
		/// </summary>
		public static string UmbracoReservedUrl{
			get{return umbracoReservedUrl;}
		}

        /// <summary>
        /// Return list of URLs that should not use compliance filter.
        /// </summary>
        public static string[] UmbracoReservedUrls
        {
            get { return umbracoReservedUrl.Split(new Char[] {','}, StringSplitOptions.RemoveEmptyEntries); }
        }
		

		/// <summary>
		/// static constructor for the reader class
		/// </summary>
		static Configuration()
		{

            XmlNode configNode = System.Web.Configuration.WebConfigurationManager.GetSection("ComplianceConfig") as XmlNode;
			
			if(configNode != null)
			{
				XmlNamespaceManager manager = new XmlNamespaceManager(configNode.OwnerDocument.NameTable);
				manager.AddNamespace("", "");
				_ApplyMCMSRules = Convert.ToBoolean(configNode.SelectSingleNode("//ApplyMCMSRules", manager).InnerText);
				_RemoveControlSpans = Convert.ToBoolean(configNode.SelectSingleNode("//RemoveControlSpans", manager).InnerText);
				_RemoveComments = Convert.ToBoolean(configNode.SelectSingleNode("//RemoveComments", manager).InnerText);
				umbracoReservedUrl = configNode.SelectSingleNode("//UmbracoReservedUrl", manager).InnerText;
                removeIDUnderScores = Convert.ToBoolean(configNode.SelectSingleNode("//RemoveIDUnderScores", manager).InnerText);
				
			}
			//if no section then we dont apply the mcms rules at all			
		}
	}
}
